const crossDomain = async (ctx, next) => {
    // 处理简单请求
    ctx.set("Access-Control-Allow-origin", "*");
    // 处理非简单请求
    ctx.set(
        "Access-Control-Allow-Headers",
        "Accept,Accept-Encoding,Accept-Language,Connection,Content-Length,Content-Type,Host,origin,Referer,User-Agent"
    );
    ctx.set("Access-Control-Allow-Credentials", true);
    ctx.set("Access-Control-Allow-Methods", "PUT,POST,GET,PATCH,DELETE,OPTIONS");
    // 处理预检请求
    if (ctx.method === "OPTIONS") {
        ctx.status = 204;
    } else {
        await next();
    }
};

export { crossDomain };
